#include "xlcomm/net/tcp_client.h"

#include <iostream>

#include "xlcomm/base/logger.h"
#include "xlcomm/net/buffer.h"
#include "xlcomm/net/detail/connector.h"
#include "xlcomm/net/detail/sockets_ops.h"
#include "xlcomm/net/event_loop.h"

using namespace xlcomm;

#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include "boost/test/unit_test.hpp"

void OnConnect(int fd) {
  char buff[] = "hello, I'm connector";
  net::sockets::write(fd, buff, strlen(buff));
}

BOOST_AUTO_TEST_CASE(Connector) {
  std::cout << "-------------Connector\n";
  Logger::SetLogLevel(Logger::kTrace);

  net::EventLoop loop;
  net::Connector connector(&loop, net::InetAddress(5555, "127.0.0.1"));
  connector.set_new_connection_callback(OnConnect);
  connector.Start();
  loop.Loop();
}